package com.audio;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder.AudioSource;

public class Recorder {

	private short[] recordedAudioBuffer;
	private int bufferRead;
	private AudioRecord recorder;
	private int recorderBufferSize = 0;

	public Recorder() {
		// the number of audio that the application should capture from the
		// microphone, the bigger the buffer, the
		// more audio that the app captures.
		recorderBufferSize = AudioRecord.getMinBufferSize(8000,
				AudioFormat.CHANNEL_CONFIGURATION_STEREO,
				AudioFormat.ENCODING_PCM_16BIT) * 100;

		recorder = new AudioRecord(AudioSource.MIC, 8000,
				AudioFormat.CHANNEL_CONFIGURATION_STEREO,
				AudioFormat.ENCODING_PCM_16BIT, recorderBufferSize);
	}

	public short[] startRecording() {

		recordedAudioBuffer = new short[recorderBufferSize];
		recorder.startRecording();

		bufferRead = recorder.read(recordedAudioBuffer, 0, recorderBufferSize);

		return recordedAudioBuffer;

	}

	public short[] getRecordedAudioBuffer() {
		return recordedAudioBuffer;
	}

	public void stopRecording() {
		recorder.stop();
		recorder.release();
	}

	public int getBufferRead() {
		return bufferRead;
	}

}